<!--
 * @Description: 客诉历史详情
 * @Autor: 何兴家
 * @Date: 2021-03-04 15:38:26
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-03-05 16:10:47
-->
<template>
  <div>
    <FormPanel ref="formPanel" :cols="4" :list="formList" :isSubmitBtn="false"></FormPanel>
    <BreakSpace label="处理明细" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
    <FilterTable
      ref="table"
      columnsRef="repair_repairReception_precontractArrange_complainHistory_detail"
      height="auto"
      :dataSource="tableDataSource"
      :isMemoryPagination="true"
      :columns="tableColumns"
      :onColumnsChange="columns => (this.tableColumns = columns)"
      :isSelectColumn="false"
    >
    </FilterTable>
    <BreakSpace label="结案信息" :containerStyle="{ marginBottom: '10px' }"></BreakSpace>
    <FormPanel ref="finallForm" :cols="3" :list="finalFormList" :labelWidth="100" :isSubmitBtn="false"></FormPanel>

    <div class="dialogBottmView">
      <el-button @click="handleCancel">取消</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';

import { getDealerUser } from '@/api/repair/common';

export default {
  props: ['formData'],
  mixins: [dictionary],
  data() {
    return {
      formList: this.createformList(),
      finalFormList: this.createFinalFormList(),
      tableColumns: this.createTableColumns(),
      tableDataSource: [] // table数据源
    };
  },
  mounted() {
    this.initDict();
    this.initPageData();
  },
  methods: {
    createformList() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '投诉信息'
        },
        {
          type: 'INPUT',
          label: '投诉人姓名',
          fieldName: 'complaintName'
        },
        {
          type: 'INPUT',
          label: '投诉人性别',
          fieldName: 'complaintGender'
        },
        {
          type: 'INPUT',
          label: '投诉人电话',
          fieldName: 'complaintPhone'
        },
        {
          type: 'SELECT',
          label: '投诉类型',
          fieldName: 'complaintType',
          itemList: [
            { text: '产品', value: 'C' },
            { text: '销售', value: 'X' },
            { text: '电桩', value: 'D' },
            { text: '服务', value: 'F' },
            { text: '配件', value: 'P' }
          ]
        },
        {
          type: 'INPUT',
          label: '投诉子类',
          fieldName: 'complaintSubtype'
        },
        {
          type: 'INPUT',
          label: '投诉日期',
          fieldName: 'complaintDate'
        },
        {
          type: 'SELECT',
          label: '处理状态',
          fieldName: 'status',
          itemList: [
            { text: '未处理', value: 'A' },
            { text: '已处理', value: 'B' }
          ]
        },
        {
          type: 'INPUT',
          label: '接待员',
          fieldName: 'receptionist'
        },
        {
          type: 'SELECT',
          label: '投诉来源',
          fieldName: 'complaintOrigin',
          itemList: [
            { text: '报道', value: 'B' },
            { text: '电话', value: 'D' },
            { text: '监督机构', value: 'J' },
            { text: '网络', value: 'W' },
            { text: '现场投诉', value: 'X' }
          ]
        },
        {
          type: 'INPUT',
          label: '来源子类',
          fieldName: 'fake1'
        },
        {
          type: 'SELECT',
          label: '投诉等级',
          fieldName: 'complaintSerious',
          itemList: [
            { text: '零级', value: 'O' },
            { text: '重大', value: 'Z' },
            { text: '一般', value: 'Y' }
          ]
        },
        {
          type: 'INPUT',
          label: '被投诉部门',
          fieldName: 'department'
        },
        {
          type: 'INPUT',
          label: '被投诉员工',
          fieldName: 'beComplainTemp'
        },
        {
          type: 'INPUT',
          label: '投诉单位',
          selfCols: 3,
          fieldName: 'complaintCorp'
        },
        {
          type: 'BREAK_SPACE',
          label: '工单信息'
        },
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo'
        },
        {
          type: 'INPUT',
          label: '开单日期',
          fieldName: 'roCreateDate'
        },
        {
          type: 'SELECT',
          label: '维修类型',
          fieldName: 'repairType',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'serviceAdvisor',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '送修人',
          fieldName: 'deliverer'
        },
        {
          type: 'INPUT',
          label: '送修人手机',
          fieldName: 'delivererMobile'
        },
        {
          type: 'INPUT',
          label: '送修人电话',
          fieldName: 'delivererPhone'
        },
        {
          type: 'SELECT',
          label: '责任技师',
          fieldName: 'technician',
          itemList: []
        },
        {
          type: 'BREAK_SPACE',
          label: '车辆信息'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin'
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName'
        },
        {
          type: 'SELECT',
          label: '车辆性质',
          fieldName: 'vehiclePurpose',
          itemList: this.createDictList('4103')
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'inMileage'
        },
        {
          type: 'INPUT',
          label: '购车日期',
          fieldName: 'salesDate'
        },
        {
          type: 'INPUT',
          label: '车主地址',
          selcCols: 2,
          fieldName: 'address'
        },
        {
          type: 'BREAK_SPACE',
          label: '投诉调查'
        },
        {
          type: 'TEXT_AREA',
          label: '投诉摘要',
          fieldName: 'complaintSummary',
          selfCols: 2,
          rows: 3
        },
        {
          type: 'TEXT_AREA',
          label: '投诉原因',
          fieldName: 'complaintReason',
          selfCols: 2,
          rows: 3
        },
        {
          type: 'TEXT_AREA',
          label: '备注信息',
          fieldName: 'remark',
          selfCols: 2,
          rows: 3
        },
        {
          type: 'TEXT_AREA',
          label: '解决方案',
          fieldName: 'resolvent',
          selfCols: 2,
          rows: 3
        }
      ];
    },
    createFinalFormList() {
      return [
        {
          type: 'SELECT',
          label: '结案状态',
          fieldName: 'jaStatus',
          itemList: [
            { text: '未结案', value: 'W' },
            { text: '正常结案可回访', value: 'C' },
            { text: '正常结案不可回访', value: 'E' },
            { text: '强制结案', value: 'D' },
            { text: '仲裁被驳回', value: 'F' },
            { text: '仲裁通过', value: 'G' }
          ]
        },
        {
          type: 'INPUT',
          label: '回访结果',
          fieldName: 'returnVisitResults'
        },
        {
          type: 'INPUT',
          label: '重新处理次数',
          fieldName: 'fake1'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '处理时间',
          dataIndex: 'handleTime'
        },
        {
          title: '处理人',
          dataIndex: 'handleBy'
        },
        {
          title: '处理人联系方式',
          dataIndex: 'phone'
        },
        {
          title: '处理结果',
          dataIndex: 'content'
        },
        {
          title: '备注',
          dataIndex: 'remarks'
        }
      ];
    },
    // 初始化字典项查询
    initDict() {
      this.queryDealerUser();
    },
    // 查询所有人员(翻译用)
    async queryDealerUser() {
      let res = await getDealerUser();
      if (res.resultCode == 200) {
        let userDicts = res.data.map(item => ({ text: item.employeeName, value: item.userId + '' }));
        findFormItem(this.formList, 'serviceAdvisor').itemList = findFormItem(this.formList, 'technician').itemList = userDicts;
      }
    },
    // 初始化页面数据
    initPageData() {
      let formTarget = [...this.formList, ...this.finalFormList];
      formTarget.forEach(item => {
        item.disabled = true;
        item.initialValue = this.formData[item.fieldName] || '';
      });
      this.tableDataSource = this.formData.complaindealwithlist;
    },
    // 点击确定
    handleCancel() {
      this.$emit('close');
    }
  }
};
</script>

<style scoped></style>
